// stores/contactStore.js
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useContactStore = defineStore('contact', () => {
  // 联系人数据
  const contacts = ref([
    {
      id: 1,
      name: '张三',
      avatar: 'https://example.com/avatar1.jpg',
      lastMessage: '你好，最近怎么样？',
      lastMessageTime: '2024-03-10T14:30:00'
    },
    {
      id: 2,
      name: '李四',
      avatar: 'https://example.com/avatar2.jpg',
      lastMessage: '项目文档已发送',
      lastMessageTime: '2024-03-10T09:15:00'
    }
  ])

  // 更新最后消息
  const updateLastMessage = (contactId, message) => {
    const contact = contacts.value.find(c => c.id === contactId)
    if (contact) {
      contact.lastMessage = message
      contact.lastMessageTime = new Date().toISOString()
    }
  }

  return { contacts, updateLastMessage }
})